﻿<cfoutput>

<div id="companies"></div>
<div id="confirmDialog" style="display: none;"></div>

#javaScriptIncludeTag("flexigrid.pack")#
#styleSheetLinkTag("flexigrid.pack")#

<script>
	$( function() {
		var addCompany = function() {
			location = "#JSSTringFormat(URLFor(action="addCompany"))#";
		};
		
		var editCompany = function() {
			location = "#JSStringFormat(URLFor(action='editCompany', params='id='))#" + $(".trSelected").attr("id");
		}
		
		var deleteCompany = function() {
			
			if ($(".trSelected").length) {
				var company = $(".trSelected :first-child :first-child").html();
				
				$("##confirmDialog").html("Delete " + company + " ?");
				
				$("##confirmDialog").dialog({
					modal : true,
					buttons : {
						"Delete" : function() {
							//$(this).dialog("close");
							location = "#JSStringFormat(URLFor(action='deleteCompany', params='id='))#" + $(".trSelected").attr("id");
						},
						"Cancel" : function() {
							$(this).dialog("close");
						}
					}
				});
			}
			
		};
		
		
		$("##companies").flexigrid({			
			url : "#URLFor(action="companyList", params="format=json")#",
			dataType : "json",
			colModel : [
				
				{
					display : "Company",
					name : "#JSStringFormat(encryptHex('companyname'))#",
					width : 200,
					sortable : true,
					align : "center"
					
				},
				{
					display : "Address",
					name : "#JSStringFormat(encryptHex('address'))#",
					width : 200,
					sortable : true,
					align : "center"
				},
				{
					display : "Phone",
					name : "#JSStringFormat(encryptHex('phone'))#",
					width : 100,
					sortable : true,
					align : "center"
				},
				{
					display : "Fax",
					name : "#JSStringFormat(encryptHex('fax'))#",
					width : 100,
					sortable : true,
					align : "center"
				}
			],
			buttons : [ 
				{
					name : 'Add',
					bclass : 'add',
					onpress : addCompany
				}, 
				{
					name : 'Edit',
					bclass : 'edit',
					onpress : editCompany
				},
				{
					name : 'Delete',
					bclass : 'delete',
					onpress : deleteCompany
				}, 
				{
					separator : true
				} 
			],
			searchitems : [
				{
					display : "Company",
					name : "#JSStringFormat(encryptHex('companyname'))#"
				},
				{
					display : "Address",
					name : "#JSStringFormat(encryptHex('address'))#"
				},
				{
					display : "Phone",
					name : "#JSStringFormat(encryptHex('phone'))#"
				},
				{
					name : "#JSStringFormat(encryptHex('fax'))#",
					name : "fax"
				}
			],
			sortname : "#JSStringFormat(encryptHex('companyname'))#",
			sortorder : "asc",
			usepager : true,
			title : "Company",
			singleSelect : true
		});
	});
</script>	

</cfoutput>